package com.raidpoints.client;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;

public class AdminBox extends DialogBox {
	RaidPoints rp;
	AsyncCallback<String> stuffCallback;
		
	public AdminBox(RaidPoints mrp) {
		setHTML("Admin Console");
		rp = mrp;
		
		LayoutPanel layoutPanel = new LayoutPanel();
		setWidget(layoutPanel);
		layoutPanel.setSize("259px", "86px");
		
		final TextBox textBox = new TextBox();
		layoutPanel.add(textBox);
		layoutPanel.setWidgetLeftWidth(textBox, 22.0, Unit.PX, 226.0, Unit.PX);
		layoutPanel.setWidgetTopHeight(textBox, 11.0, Unit.PX, 32.0, Unit.PX);
		
		Button btnNewButton = new Button("Run");
		layoutPanel.add(btnNewButton);
		layoutPanel.setWidgetLeftWidth(btnNewButton, 32.0, Unit.PX, 81.0, Unit.PX);
		layoutPanel.setWidgetTopHeight(btnNewButton, 49.0, Unit.PX, 28.0, Unit.PX);
		
		Button btnClose = new Button("Close");
		layoutPanel.add(btnClose);
		layoutPanel.setWidgetLeftWidth(btnClose, 147.0, Unit.PX, 81.0, Unit.PX);
		layoutPanel.setWidgetTopHeight(btnClose, 49.0, Unit.PX, 28.0, Unit.PX);
		
		stuffCallback = new AsyncCallback<String>(){

			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onSuccess(String result) {
				Window.alert(result);				
			}
			
		};
		
		btnClose.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				hide();				
			}
		});
		
		
		btnNewButton.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				rp.rpsvc.DoStuff(textBox.getText(), stuffCallback);
				hide();				
			}
		});
	}
}
